package ar.edu.unicen.exa.isistan.archassis.source;

import java.util.ArrayList;
import java.util.List;

import ar.edu.unicen.exa.isistan.archassis.DiffRequestData;
import ar.edu.unicen.exa.isistan.archassis.actions.IAction;
import ar.edu.unicen.exa.isistan.archassis.diff.IDiffStrategy;
import ar.edu.unicen.exa.isistan.archassis.diff.JavaDiffFacade;
import ar.edu.unicen.exa.isistan.archassis.ia.api.db.JavaClass;
import ar.edu.unicen.exa.isistan.archassis.metadata.ClassResolver;
import ar.edu.unicen.exa.isistan.archassis.rcs.IRevisionControlSystem;
import ar.edu.unicen.exa.isistan.archassis.rcs.IVersion;
import ar.edu.unicen.exa.isistan.archassis.rcs.RCSFacade;

public class RCSSourceStrategy implements ISourceStrategy {
	private IRevisionControlSystem rcs;
	private IVersion versionFrom;
	private IVersion versionTo;
	public RCSSourceStrategy(IRevisionControlSystem rcs, IVersion versionFrom, IVersion versionTo) {
		this.rcs = rcs;
		this.versionFrom = versionFrom;
		this.versionTo = versionTo;
	}
	@Override
	public List<JavaClass> getJavaClassList(IDiffStrategy diffStrategy) {
		try {
			//TODO este metodo habria que traerlo para aquí
			RCSFacade.getInstance().download(rcs, versionFrom, versionTo);
		} catch (Exception e) {
			e.printStackTrace();
			return new ArrayList<JavaClass>();
		}
		
		DiffRequestData tempFile = rcs.getDiffRequestData();
		ClassResolver classResolver = new ClassResolver(tempFile.getDestinationFor(versionTo));
		
		List<IAction> actions = JavaDiffFacade.compare(rcs.getDiffRequestData(), versionFrom, versionTo, classResolver);
		
		return diffStrategy.getJavaClassList(actions, classResolver);
	}
	
	public IRevisionControlSystem getRcs() {
		return rcs;
	}
	public IVersion getVersionFrom() {
		return versionFrom;
	}
	public IVersion getVersionTo() {
		return versionTo;
	}

	
}
